import { lazyBatchReport } from '../report/index'
import { generateUniqueId } from '../utils/index'

export default function onClick() {
  ;['mousedown', 'touchstart'].forEach((eventName) => {
    window.addEventListener(eventName, (event) => {
      const target = event.target
      if (target && target.tagName) {
        const reportData = {
          uuid: generateUniqueId(),
          type: 'behavior',
          subType: 'click',
          target: target.tagName,
          startTime: event.timeStamp,
          innerHTML: target.innerHTML,
          outerHTML: target.outerHTML,
          width: target.offsetWidth,
          height: target.offsetHeight,
          path: event.path,
          scrollTop: document.documentElement.scrollTop || document.body.scrollTop,
        }

        lazyBatchReport(reportData)
      }
    })
  })
}
